import matplotlib
matplotlib.use('TkAgg')  # 或者根据你的系统选择合适的后端
import matplotlib.pyplot as plt
from matplotlib import rcParams
import pandas as pd

rcParams['font.family'] = 'STHeiti'  # Mac
# rcParams['font.sans-serif'] = ['SimHei', 'Microsoft YaHei', 'SimSun', 'FangSong', 'KaiTi']
rcParams['axes.unicode_minus'] = False  # 解决负号显示问题

# 导入数据
df = pd.read_csv('../data/pd_data/weather.csv')

df['date'] = pd.to_datetime(df['date'])
print(df.head())
print(df.info())
df = df[df['date'].dt.year == 2015]

# 绘制温度的趋势变化图
plt.figure(figsize=(10, 8))
plt.plot(df['date'], df['temp_max'], color='red', label='最高气温')
plt.plot(df['date'], df['temp_min'], color='orange', label='最低气温')

plt.title('2015年气温趋势变化图')
plt.xlabel('日期')
plt.ylabel('气温')

# plt.legend(loc='upper left')
plt.legend()
plt.show()


# 绘制降水量的直方图
plt.hist(df['precipitation'], bins=5)
plt.xlabel('降水量')
plt.ylabel('所占天数')
plt.show()

